//
//  DLNetWorkErrorView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/22.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLNetWorkErrorView.h"

@interface DLNetWorkErrorView ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, copy) void (^networkRetryBlock)(void);

@end

@implementation DLNetWorkErrorView



- (instancetype)initWithNetworkRetry:(void (^)(void))networkRetry {
    if (self = [super init]) {
        
        self.networkRetryBlock = networkRetry;
        [self initializeUI];
    }
    return self;
}

- (void)networkRetryAction:(UITapGestureRecognizer *)tap {
    if (self.networkRetryBlock) {
        self.networkRetryBlock();
    }
}

- (void)initializeUI {
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(networkRetryAction:)]];
    [self addSubview:self.imageView];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth, kScreenHeight));
    }];
    self.backgroundColor = [UIColor whiteColor];
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        if (kScreenWidth == 320) {
            if (kScreenSafeAreaHeight == 640) {
                _imageView.image = [UIImage imageNamed:@"404-640x960.jpg"];
            } else {
                _imageView.image = [UIImage imageNamed:@"404-640x1136.jpg"];
            }
        } else if (kScreenWidth == 375) {
            _imageView.image = [UIImage imageNamed:@"404-750×1334.jpg"];
        } else if (kScreenWidth == 414) {
            _imageView.image = [UIImage imageNamed:@"404-1242x2208.jpg"];
        } else {
            _imageView.image = [UIImage imageNamed:@"404-1125x2436.jpg"];
        }
        _imageView.backgroundColor = [UIColor whiteColor];
    }
    return _imageView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
